package com.zjitc.book.common.exception;

import cn.hutool.http.HttpStatus;
import com.zjitc.book.common.result.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.Map;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {//全局异常处理器（例外：springSecurity：要看谁先捕获异常
    //所有的异常都会进入这个方法
    @ExceptionHandler(Exception.class)
    public R<String> handleException(Exception ex){
        log.warn("{}-{}",ex.getMessage(),(ex.getCause()==null?"根因未知":ex.getCause()));
        return R.error(HttpStatus.HTTP_INTERNAL_ERROR,ex.getMessage());
    }
}
